<?php
class Withdraw_orders_model extends BZ_Model
{
    protected $_table  = 'withdraw_orders';
    protected $_table1 = 'order_base';
    
    /**
     * 扫码用户提现记录
     */
    public function page_list($params, $start, $count)
    {
        $params = array_map('trim', $params);
        $this->db->select('profit_amount, order_base.order_id, order_base.goods_num, order_base.goods_name, cat_id, price, amount_fee, phone, sfz, number, payer_name, usetime, ordertime, other_id');
        $this->db->from($this->_table);
        $this->db->join($this->_table1, 'withdraw_orders.order_id = order_base.order_id', 'INNER');

        $this->db->where_in("withdraw_orders.withdraw_id", $params['withdraw_id']); //提现用户
        $this->db->where('calculate_method', 3); //扫码的来的订单

        if ( ! empty($params['order_id'])) {
            $this->db->where("order_base.order_id", $params['order_id']);
        }

        $this->db->order_by('order_base.order_id', 'DESC');
        $this->db->limit($start, $count);
        return $this->db->get();
    }

    /**
     * 统计总数
     */
    public function total($params)
    {
        $params = array_map('trim', $params);
        $this->db->select('*');
        $this->db->from($this->_table);
        $this->db->join($this->_table1, 'withdraw_orders.order_id = order_base.order_id', 'INNER');

        $this->db->where_in("withdraw_orders.withdraw_id", $params['withdraw_id']); //提现用户
        $this->db->where('calculate_method', 3); //扫码的来的订单

        if ( ! empty($params['order_id'])) {
            $this->db->where("order_base.order_id", $params['order_id']);
        }

        return $this->db->count_all_results();
    }

    /**
     * 导出订单
     * @param array $params
     */
    public function excelExport($params)
    {
        $this->db->select('order_base.order_id,order_base.goods_name,order_base.play_name,order_base.phone,order_base.sfz,order_base.payer_name,order_base.number,profit_amount,order_base.other_id,FROM_UNIXTIME(`order_base`.`ordertime`),IF(`order_base`.`usetime`=0,order_base.usetime,FROM_UNIXTIME(`order_base`.`usetime`))');
        $this->db->from($this->_table);
        $this->db->join($this->_table1, 'withdraw_orders.order_id = order_base.order_id', 'INNER');

        $this->db->where_in("withdraw_orders.withdraw_id", $params['withdraw_id']); //提现用户
        $this->db->where('calculate_method', 3); //扫码的来的订单

        $this->db->order_by('order_base.order_id', 'DESC');
        return $this->db->get();
    }
}